<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
	<body>
		<script>
			// 归并排序
			let arr = [16, 24, 37, 39, 15, 19, 27, 35];
			let temp = [];
			function sort(arr,low,high,mid) {
				// debugger
				let i,j,k;
				for(k = low;k<=high;k++){
					temp[k] = arr[k];
				}
				for(i = low,j=mid+1,k=i;i<=mid&&j<=high;k++){
					if(temp[i] <= temp[j]){
						arr[k] = temp[i++];
					}else{
						arr[k] = temp[j++];
					}
				}
				while(i<=mid){
					arr[k++] = temp[i++];
				}
				while(j<=high){
					arr[k++] = temp[j++]
				}
				return arr;
			}
			let i = 0;
			let h = arr.length-1;
			let m = Math.floor((i + h)/2);
			console.log(sort(arr, i, h, m));
		</script>
	</body>
</html>
